package com.academic_system.mapper;

import com.academic_system.model.PartyActivity;
import com.academic_system.model.PartyActivityConditions;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author 20155880 房雁颖
 * @description 党支部活动Dao层
 * @project_name PartyActivityDao
 * @package com.academic_system.dao
 * @create 2018-11-13 8:22
 **/
@Repository
public interface PartyActivityDao {
    /**
     * @param partyActivity
     * @Description 党支部活动录入
     * @author 20155880 房雁颖
     * @methodName addPartyActivity
     * @returnType boolean
     * @create 2018/11/16 8:45
     **/
    @Insert("insert into party_activity(party_info_id,party_organization_num,party_activity_name,party_activity_time,party_activity_description) " +
            "values(#{partyActivity.partyOrganizationNum},#{partyActivity.partyOrganizationNum},#{partyActivity.partyActivityName},#{partyActivity.partyActivityTime},#{partyActivity.partyActivityDescription})")
    boolean addPartyActivity(@Param("partyActivity")PartyActivity partyActivity, @Param("id")int id);

//    /**
//     * @param partyActivity
//     * @Description 党支部活动修改，保存,临时表
//     * @author 20155880 房雁颖
//     * @methodName savePartyActivity
//     * @returnType boolean
//     * @create 2018/11/16 8:45
//     **/
//    @Insert("insert into party_activity_temp(party_activity_id,party_info_id,party_organization_num,party_activity_name,party_activity_time,party_activity_description) " +
//            "values(#{partyActivity.partyActivityId},#{partyActivity.partyOrganizationNum},#{partyActivity.partyOrganizationNum},#{partyActivity.partyActivityName},#{partyActivity.partyActivityTime},#{partyActivity.partyActivityDescription})")
//    boolean savePartyActivityTemp(@Param("partyActivity")PartyActivity partyActivity, @Param("id")int id);

    /**
     * @param partyActivity
     * @Description 党支部活动修改，保存，活动表
     * @author 20155880 房雁颖
     * @methodName savePartyActivity
     * @returnType boolean
     * @create 2018/11/16 8:45
     **/
    @Update("update party_activity set party_activity_name=#{partyActivity.partyActivityName},party_activity_time=#{partyActivity.partyActivityTime},party_activity_description=#{partyActivity.partyActivityDescription},state=1 " +
            " where party_activity_id=#{partyActivity.partyActivityId}")
    boolean savePartyActivity(@Param("partyActivity")PartyActivity partyActivity);

//    /**
//     * @param party_activity_id
//     * @Description 党支部活动修改，提交，临时表（删除临时表）
//     * @author 20155880 房雁颖
//     * @methodName deletePartyActivityTemp
//     * @returnType boolean
//     * @create 2018/11/16 8:45
//     **/
//    @Delete("delete from party_activity_temp where party_activity_id=#{party_activity_id}")
//    boolean deletePartyActivityTemp(@Param("party_activity_id") int party_activity_id);

    /**
     * @param partyActivity
     * @Description 党支部活动修改，提交，活动表
     * @author 20155880 房雁颖
     * @methodName commitPartyActivity
     * @returnType boolean
     * @create 2018/11/16 8:45
     **/
    @Update("update party_activity set party_activity_name=#{partyActivity.partyActivityName},party_activity_time=#{partyActivity.partyActivityTime},party_activity_description=#{partyActivity.partyActivityDescription},state=0 " +
            " where party_activity_id=#{partyActivity.partyActivityId}")
    boolean commitPartyActivity(@Param("partyActivity")PartyActivity partyActivity);



//    /**
//     * @param partyActivity
//     * @Description 覆盖临时表
//     * @author 20155880 房雁颖
//     * @methodName coverPartyActivity
//     * @returnType boolean
//     * @create 2018/11/16 8:45
//     **/
//    @Update("update party_activity_temp set party_activity_name=#{partyActivity.partyActivityName},party_activity_time=#{partyActivity.partyActivityTime},party_activity_description=#{partyActivity.partyActivityDescription} " +
//            "where party_activity_id=#{partyActivity.partyActivityId}")
//    boolean coverPartyActivityTemp(@Param("partyActivity")PartyActivity partyActivity);

//    /**
//     * @param party_organization_num
//     * @Description 查询临时表是否有该活动记录
//     * @author 20155880 房雁颖
//     * @methodName queryPartyActivityTemp
//     * @returnType PartyActivityTemp
//     * @create 2018/11/16 8:45
//     **/
//    @Select("select * from party_activity_temp where party_activity_id=#{party_activity_id}")
//    PartyActivityTemp queryPartyActivityTemp(@Param("party_organization_num")int party_organization_num);







    /**
     * @param party_activity_id
     * @Description 党支部活动删除
     * @author 20155880 房雁颖
     * @methodName deletePartyActivity
     * @returnType boolean
     * @create 2018/11/16 8:45
     **/
    @Delete("delete from party_activity where party_activity_id=#{party_activity_id}")
    boolean deletePartyActivity(@Param("party_activity_id") int party_activity_id);

    /**
     * @param partyActivityConditions
     * @Description 党支部活动动态查询(按活动名称、活动时间),活动表
     * @author 20155880 房雁颖
     * @methodName queryPartyActivityByConditions
     * @returnType List
     * @create 2018/11/16 8:45
     **/
    @SelectProvider(type = PartyActivitySqlProvider.class, method = "queryPartyActivityByConditions")
    List<PartyActivity> queryPartyActivityByConditions(PartyActivityConditions partyActivityConditions);


    /**
     * @param partyActivityConditions
     * @Description 党支部活动动态查询(按活动名称、活动时间),活动表
     * @author 20155880 房雁颖
     * @methodName queryPartyActivityByConditionsByCache
     * @returnType List
     * @create 2018/11/16 8:45
     **/
    @SelectProvider(type = PartyActivitySqlProvider.class, method = "queryPartyActivityByConditionsByCache")
    List<PartyActivity> queryPartyActivityByConditionsByCache(PartyActivityConditions partyActivityConditions);
//    /**
//     * @param partyActivityConditions
//     * @Description 党支部活动动态查询(按活动名称、活动时间)，临时表
//     * @author 20155880 房雁颖
//     * @methodName queryPartyActivityTempByConditions
//     * @returnType List
//     * @create 2018/11/16 8:45
//     **/
//    @SelectProvider(type = PartyActivitySqlProvider.class, method = "queryPartyActivityTempByConditions")
//    List<PartyActivityTemp> queryPartyActivityTempByConditions(PartyActivityConditions partyActivityConditions);

    /**
     * @param party_organization_num
     * @Description 党支部活动统计，通过党支部编号
     * @author 20155880 房雁颖
     * @methodName countActivity
     * @returnType int
     * @create 2018/11/16 8:45
     **/
    @Select("select count(*) from party_activity where party_organization_num=#{party_organization_num}")
    int countActivity(@Param("party_organization_num")int party_organization_num);

    /**
     * @param party_activity_id
     * @Description 通过党支部活动ID查找党支部活动信息,活动表
     * @author 20155880 房雁颖
     * @methodName queryPartyActivityById
     * @returnType PartyActivity
     * @create 2018/11/16 8:45
     **/
    @Select("select * from party_activity where party_activity_id=#{party_activity_id}")
    PartyActivity queryPartyActivityById(@Param("party_activity_id")int party_activity_id);

//    /**
//     * @param party_activity_id
//     * @Description 通过党支部活动ID查找党支部活动信息,临时表
//     * @author 20155880 房雁颖
//     * @methodName queryPartyActivityTempById
//     * @returnType PartyActivity
//     * @create 2018/11/16 8:45
//     **/
//    @Select("select * from party_activity_temp where party_activity_id=#{party_activity_id}")
//    PartyActivityTemp queryPartyActivityTempById(@Param("party_activity_id")int party_activity_id);


    /**
     * @param party_activity_id
     * @Description 通过党支部活动ID查找党支部名称
     * @author 20155880 房雁颖
     * @methodName queryPartyNameByPAI
     * @returnType String
     * @create 2018/11/16 8:45
     **/
    @Select("select party_name from party where party_organization_num=(select party_organization_num from party_activity where party_activity_id=#{party_activity_id})")
    String queryPartyNameByPAI(@Param("party_activity_id")int party_activity_id);


}
